<?php
// call 'social.user.login' with [username, password] as session_key
class Twis_Template_TokenParser_Call extends Twig_TokenParser
{
    public function parse(Twig_Token $token)
        {
        $lineno = $token->getLine();
        $method = $this->parser->getStream()->expect(Twig_Token::STRING_TYPE)->getValue();

        // with
        $params = null;
        if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'with')) {
            $this->parser->getStream()->next();
            $params = $this->parser->getExpressionParser()->parseExpression();
        }

        // as
        $this->parser->getStream()->expect(Twig_Token::NAME_TYPE, 'as');
        $varname = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();

        $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);

        return new Twis_Template_Node_Call($method, $params, $varname, $lineno, $this->getTag());
    }

    public function getTag()
    {
        return 'call';
    }
}
